package com.mengzaiwang.book.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mengzaiwang.book.mapper.UserMapper;
import com.mengzaiwang.book.pojo.Book;
import com.mengzaiwang.book.pojo.BookPageDO;
import com.mengzaiwang.book.pojo.BookPageDTO;
import com.mengzaiwang.book.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 猛在王
 * @version 1.0
 * @date 27/6/2024 下午5:19
 * @description UserServiceImpl
 * @since 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 分页查询
     * @return
     */
    public BookPageDO page(BookPageDTO bookPageDTO) {
        //创建BookPageDo对象
        BookPageDO bookPageDO = new BookPageDO();
        //开启分页查询
        PageHelper.startPage(bookPageDTO.getPageNum(), bookPageDTO.getPageSize());
        //调用mapper开启分页查询
        Page<Book> books = userMapper.page(bookPageDTO);
        bookPageDO.setTotal(books.getTotal());
        bookPageDO.setBooks(books);
        return bookPageDO;
    }

}
